package com.dao;

import com.pojo.Dept;
import com.pojo.Page;
import com.utils.DSUtil;

import java.util.ArrayList;
import java.util.List;

public class DeptDao {
    public ArrayList<Dept> queryDept() {
        return DSUtil.query("select * from dept limit 0,5", Dept.class);

    }
    public ArrayList<Dept> queryDept(int nowPage) {
        return DSUtil.query("select * from dept limit ?,?", Dept.class,(nowPage-1)*5,5);

    }

    public void delete(String id) {
        DSUtil.execute("delete from dept where id = ?", id);
    }

    public void insert(Dept d) {
        DSUtil.execute("insert into dept(name,address) values(?,?)",d.getName(),d.getAddress());
    }



    public List<Dept> editDept(String id) {
        return DSUtil.query("select * from dept where id = ?", Dept.class, id);
    }

    public void update(String id,String name,String address) {
        DSUtil.execute("update dept set name = ?,address = ? where id = ?", name,address,id);
    }

    public List<Dept> getSearch(String s) {
        s = "%"+s+"%";
        return DSUtil.query("select * from dept where name like ? or id like ? or address like ?", Dept.class, s,s,s);
    }

    public int queryPages() {
        return DSUtil.query("select count(*) as page from dept", Page.class).get(0).getPage();

    }

}
